<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Javascript tree with multiple select</title>
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="../extra/css/gridless.css">
    <link rel="stylesheet" href="../extra/prism/prism.css">
    <link rel="stylesheet" href="example.css">
    <link rel="stylesheet" href="../jqtree.css">
    <!--[if lt IE 9]>
        <script src="../extra/js/jquery-1.10.2.min.js"></script>
    <![endif]-->
    <!--[if gte IE 9]><!-->
        <script src="../extra/js/jquery-2.0.3.min.js"></script>
    <!--<![endif]-->
    <script src="../extra/prism/prism.js"></script>
    <script src="../extra/js/jquery.mockjax.js"></script>
    <script src="../extra/example_data.js"></script>
    <script src="../tree.jquery.js"></script>
    <script type="text/javascript">
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', 'UA-33742133-1']);
        _gaq.push(['_trackPageview']);

        (function() {
            var ga = document.createElement('script');
            ga.type = 'text/javascript';
            ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0];
            s.parentNode.insertBefore(ga, s);
        })();
    </script>
</head>
<body>
    <p id="nav">
        <a href="autoscroll.html">&laquo; Example 7</a>
        
    </p>

    <h1>Example 8 - multiple select</h1>

    
    <p>
        This example implements multiple select using the following functions and events:
    </p>
    <ul>
        <li>
            <strong>addToSelection</strong>: add node to selections
        </li>
        <li>
            <strong>isNodeSelected</strong>: is this node selected?
        </li>
        <li>
            <strong>removeFromSelection</strong>: unselect this node
        </li>
        <li>
            <strong>tree.click event</strong>: this event is fired when a user clicks on a node
        </li>
    </ul>

    <div id="tree1"></div>

    <h3>html</h3>

<pre><code class="language-markup">
&lt;div id="tree1" data-url="/nodes/"&gt;&lt;/div&gt;
</code></pre>

    <h3>javascript</h3>

<pre><code class="language-javascript">
$(function() {
    var $tree = $('#tree1');
    $tree.tree({
        data: ExampleData.example_data,
        autoOpen: true,
    });
    $tree.bind(
        'tree.click',
        function(e) {
            // Disable single selection
            e.preventDefault();

            var selected_node = e.node;

            if ($tree.tree('isNodeSelected', selected_node)) {
                $tree.tree('removeFromSelection', selected_node);
            }
            else {
                $tree.tree('addToSelection', selected_node);
            }
        }
    );
});
</code></pre>

    <script>
        $(function() {
            var $tree = $('#tree1');
            $tree.tree({
                data: ExampleData.example_data,
                autoOpen: true,
            });
            $tree.bind(
                'tree.click',
                function(e) {
                    // Disable single selection
                    e.preventDefault();

                    var selected_node = e.node;

                    if ($tree.tree('isNodeSelected', selected_node)) {
                        $tree.tree('removeFromSelection', selected_node);
                    }
                    else {
                        $tree.tree('addToSelection', selected_node);
                    }
                }
            );
        });
    </script>

</body>
</html>